package org.tis.tools.operatelog.module.log.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.LogDataChange;
import org.tis.tools.operatelog.module.log.service.ILogDataChangeService;
import org.tis.tools.starter.mybatisplus.querykit.model.Query;

import javax.validation.constraints.NotBlank;

/**
 * Created by chenchao
 * Created on 2018/6/1 20:33
 */
@RestController
@RequestMapping("/v1/api/logChange")
@Validated
public class LogDataChangeController extends BaseController<LogDataChange> {

    @Autowired
    private ILogDataChangeService logDataChangeService;

    @ApiOperation(value = "根据操作数据GUID分页查询日志差异值",notes = "传入分页数据,和操作数据GUID(guidData)值作为参数")
    @PostMapping("/pageByDataId")
    public ResultVO page(@RequestBody @Validated Query<LogDataChange> query) {
        return ResultVO.success("查询成功", logDataChangeService.queryPageById(query.getPageObj(),query.getWrapper()));
    }


    @ApiOperation(value = "根据GUID查询日志差异值",notes = "传入guid作为参数")
    @GetMapping("/{id}")
    public ResultVO detial(@PathVariable("id") @NotBlank(message = "GUID不能为空") String id) {
        LogDataChange logDataChangeQue = logDataChangeService.selectById(id);
        if (logDataChangeQue == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", logDataChangeQue);
    }
}
